package com.zmc.dynamic.controller;

import com.alibaba.fastjson.JSON;
import com.zmc.dynamic.service.StudentService;
import com.zmc.dynamic.domain.Student;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;


@RestController
@RequestMapping(value = "student/")
public class StudentController {

    @Resource
    private StudentService studentService;

    @RequestMapping("save")
    public String save(){
        Student student = new Student();
        student.setCore(80);
        student.setName("李斯");
        studentService.save(student);
        return JSON.toJSONString(student);
    }

    @RequestMapping("update/{id}")
    public String update(@PathVariable("id") Long id){
        Student student = studentService.getByStudentId(id);
        student.setName("wwwwwww");
        student.setCore((int)Math.random() * 100);
        studentService.updateStudent(student);
        return JSON.toJSONString(student);
    }

    @RequestMapping("get")
    public String get(){
        List<Student> list = studentService.list();
        return JSON.toJSONString(list);
    }

}
